package com.example.jbmsuppliers.sinopec.net;

import android.os.Bundle;
import android.os.Handler;

import com.jbm.jbmsupplier.util.ICertAddress;
import com.jbm.jbmsupplier.util.ICertAddressCtrl;
import com.jbm.jbmsupplier.util.IJOrderCtrl;
import com.jbm.jbmsupplier.util.IOrder;
import com.jbm.jbmsupplier.util.IOrderCtrl;
import com.jbm.jbmsupplier.util.IorderEntity;
import com.jbm.jbmsupplier.util.Media;
import com.jbm.jbmsupplier.util.abstracts.SendMessageInterfase;

import java.io.InputStream;

/**
 * Created by 李征 on 2017/2/27.
 */

public class NetAddRess extends SendMessageInterfase {
    private  Handler handler;
    private Bundle mBundle;
    private Media m;
    private final String cmd_key="CMDKEY";
    private final String ADDRESS="ADDRESSSHOW";
    private final String ADDRESSMESSAGE="ADDRESSMESSAGE";
    private final String REMOVEAD="REMOVEAD";
    private final String GETALLORDER="GETALLORDER";
    private final String GETDQRORDER="GETDQRORDER";
    private final String GETZYZORDER="GETZYZORDER";
    private final String GETDPJORDER="GETDPJORDER";
    private final String ORDERITEM="ORDERITEM";
    private final String ORDERINPUT="ORDERINPUT";
    private final String ORDERTEMP="ORDERTEMP";
    private final String RATING="RATING";
    private final String REPAIS="REPAIS";
    private final String MEDIAIPC="MEDIAIPC";
    private final String BAOXIU="BAOXIU";





    public NetAddRess(Handler handler) {
        this.handler = handler;
    }

    @Override
    protected void RunContext() {
        String cmd = this.mBundle.getString(cmd_key);
        if (cmd.equals(ADDRESS)){//获取地址信息
            ICertAddressCtrl addressCtrl = gSocket.GetMyCAddr(0);
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("address"),addressCtrl));

        }else if (cmd.equals(ADDRESSMESSAGE)){//添加地址信息
            String address = this.mBundle.getString("address");
            String mobile = this.mBundle.getString("contacts");
            String contats = this.mBundle.getString("mobile");
            ICertAddress addressCtrl = gSocket.AddMyCAddr(0, "", address, "", contats, mobile, "");
            addressCtrl.gi_text = address;
            addressCtrl.contacts = contats;
            addressCtrl.mobile = mobile;
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("addressmess"),addressCtrl));
        }else if (cmd.equals(REMOVEAD)){//删除地址信息
            ICertAddress result = gSocket.RemoveMyCAddr(this.mBundle.getInt("addid"), 0);
            if (result!=null)
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("Removeadd"),result));
        } else  if (cmd.equals(GETALLORDER)){//查看全部订单
            IOrderCtrl resorder = gSocket.GetMyOrderListN("'temp','new','confirm','completed','revoke','comment'", "", "", 0, this.mBundle.getInt("num"));
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),resorder));
        }else if (cmd.equals(GETDQRORDER)){//查看待确认订单
            IOrderCtrl resorder = gSocket.GetMyOrderListN("'temp','new'", "", "", 0, this.mBundle.getInt("num"));
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),resorder));
        }else if (cmd.equals(GETZYZORDER)){//查看作业中订单
            IOrderCtrl resorder =gSocket.GetMyOrderListN("'confirm'", "", "", 0, this.mBundle.getInt("num"));
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),resorder));
        }else if (cmd.equals(GETDPJORDER)){//查看带评价订单
            IOrderCtrl resorder = gSocket.GetMyOrderListN("'completed'", "", "", 0, this.mBundle.getInt("num"));;
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),resorder));
        }else if (cmd.equals(ORDERITEM)){//获取每一天的详情
            IorderEntity orderitem = gSocket.LoadOrderInfo(Integer.parseInt(this.mBundle.getString("orderid")));
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),orderitem));
        }else if (cmd.equals(ORDERINPUT)){//获取到图片
            InputStream orderinput = gSocket.InputStreamMedia(Integer.parseInt(this.mBundle.getString("orderid")), "iorder", m);
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),orderinput));
        }else if (cmd.equals(ORDERTEMP)){//取消订单类型
            IOrder orderitem =gSocket.RevokeOrder(Integer.parseInt(this.mBundle.getString("orderid")));
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),orderitem));
        }else if (cmd.equals(RATING)){//评价
            IOrder rating = gSocket.CommentOrder(Integer.parseInt(this.mBundle.getString("orid")), this.mBundle.getString("str"), this.mBundle.getInt("a"), this.mBundle.getInt("b"), this.mBundle.getInt("c"));
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("getorder"),rating));

        }else  if (cmd.equals(REPAIS)){//报修
            final IOrder id = gSocket.CreateOrder(0, this.mBundle.getInt("show"), this.mBundle.getString("edit"), "service", "pub_ent_guard", true, "");
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("repais"),id));
        }else if (cmd.equals(MEDIAIPC)){//图片上传
            Media ipc = gSocket.UploadMedia(this.mBundle.getInt("id"), "iorder", m);
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("mehand"),ipc));
        }else  if (cmd.equals(BAOXIU)){
            IJOrderCtrl baoxiu = gSocket.GetJOrderList(Integer.parseInt(this.mBundle.getString("baoxiu")), 0, 0);
            handler.sendMessage(handler.obtainMessage(this.mBundle.getInt("baohand"),baoxiu));


        }

    }

    public void AddressMessage(int Address){//查看已填加的地址
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, ADDRESS);
        this.mBundle.putInt("address",Address);
        this.Run();

    }

    public void setMediaipc(int id,Media m,int mehand){//上传图片

        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, MEDIAIPC);
         this.m=m;
        this.mBundle.putInt("id",id);
        this.mBundle.putInt("mehand",mehand);
        this.Run();



    }





    public void setRepais(int show,String edit,int repais){
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, REPAIS);
        this.mBundle.putString("edit", edit);
        this.mBundle.putInt("show",show);
        this.mBundle.putInt("repais",repais);
        this.Run();



    }



    public void AddAddressList(String address, String contacts, String mobile,int addressmess) { //没有地址进行添加
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, ADDRESSMESSAGE);
        this.mBundle.putString("address", address);
        this.mBundle.putString("contacts", contacts);
        this.mBundle.putString("mobile", mobile);
        this.mBundle.putInt("addressmess",addressmess);
        this.Run();
    }
    public void RemoveAddress(int  addid,int Removeadd){//删除每一天地址
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, REMOVEAD);
        this.mBundle.putInt("addid",addid);
        this.mBundle.putInt("Removeadd",Removeadd);
        this.Run();
    }
public void getAllOrder(int  num,int getorder){//获取全部订单
    this.mBundle = new Bundle();
    this.mBundle.putString(cmd_key, GETALLORDER);
    this.mBundle.putInt("num",num);
    this.mBundle.putInt("getorder",getorder);
    this.Run();
}

    public void getDqrOrder(int  num,int getorder){//获取待确认订单
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, GETDQRORDER);
        this.mBundle.putInt("num",num);
        this.mBundle.putInt("getorder",getorder);
        this.Run();
    }

    public void getZyzOrder(int  num,int getorder){//获取作业中订单
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, GETZYZORDER);
        this.mBundle.putInt("num",num);
        this.mBundle.putInt("getorder",getorder);
        this.Run();
    }

    public void getdPJOrder(int  num,int getorder){//获取作业中订单
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, GETDPJORDER);
        this.mBundle.putInt("num",num);
        this.mBundle.putInt("getorder",getorder);
        this.Run();
    }

public void getOrderitem(String  orderid,int getorder){//获取点击那一条
    this.mBundle = new Bundle();
    this.mBundle.putString(cmd_key, ORDERITEM);
    this.mBundle.putString("orderid", orderid);
    this.mBundle.putInt("getorder",getorder);
    this.Run();

}
    public void getOrderinput(String  orderid, Media me, int getorder){//详情订单
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, ORDERINPUT);
        this.m=me;
        this.mBundle.putString("orderid", orderid);
        this.mBundle.putInt("getorder",getorder);

        this.Run();

    }

    public void getOrderCancel(String  orderid, String state, int getorder){//取消订单
        this.mBundle = new Bundle();
            this.mBundle.putString(cmd_key, ORDERTEMP);
            this.mBundle.putString("orderid", orderid);
            this.mBundle.putInt("getorder", getorder);
        this.Run();

    }
 public void getRating(String orid,String str,int a,int b,int c,int getorder){//评价星级

     this.mBundle = new Bundle();
     this.mBundle.putString(cmd_key, RATING);
     this.mBundle.putString("orid", orid);
     this.mBundle.putString("str", str);
     this.mBundle.putInt("a", a);
     this.mBundle.putInt("b", b);
     this.mBundle.putInt("c", c);
     this.mBundle.putInt("getorder", getorder);
     this.Run();


}

    public void getBaoXiuXinxi(String baoxiu,int baohand){
        this.mBundle = new Bundle();
        this.mBundle.putString(cmd_key, BAOXIU);
        this.mBundle.putString("baoxiu", baoxiu);
        this.mBundle.putInt("baohand", baohand);
        this.Run();


    }





}
